import { connect } from 'react-redux'
import { addTodo } from '@/store/actions'

const AddTodo = (props) => {
  let input
  return (
    <div>
      <form onSubmit={e=>{
        console.log(props)
        e.preventDefault()
        if(!input.value.trim()) return
        props.dispatch(addTodo(input.value))
        input.value = '' 
      }}>
        <input ref={node=>(input=node)} />
        <button type="submit">Add Todo</button>
      </form>
    </div>
  )
}

export default connect()(AddTodo)